package com.smbms.service.impl;

import com.smbms.dao.ProMapper;
import com.smbms.pojo.Provider;
import com.smbms.service.ProService;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.Duration;
import java.util.List;

/**
 * 类名：ProServletImpl
 * 作者：小涛
 * 创建时间：2021/8/25-20:42
 * 功能：
 */
@Service
public class ProServiceImpl implements ProService {

    @Resource
    private ProMapper proMapper;
    @Resource
    private RedisTemplate<String, Object> redisTemplate;
    @Override
    public List<Provider> findAllPro() {
        //判断缓存
        String key = "allProvider";
        if (redisTemplate.hasKey(key)) {
            return (List<Provider>) redisTemplate.opsForValue().get(key);
        }
        List<Provider> providerList = proMapper.findAll();
        redisTemplate.opsForValue().set(key,providerList, Duration.ofHours(6));
        return providerList;
    }
}
